package com.yuyz.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yuyz.count.MonitorCountRun;
import com.yuyz.service.ConsumerService;
import com.yuyz.service.HelloService;

import org.springframework.stereotype.Service;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Service
public class ConsumerServiceImpl implements ConsumerService {

    private final ThreadLocal<ScheduledExecutorService> scheduledExecutorService = ThreadLocal.withInitial(() -> Executors.newScheduledThreadPool(1));

    @Reference
    HelloService helloService;

    @Override
    public void method() {
        // 启动线程，每5秒钟执行一次
        scheduledExecutorService.get().scheduleWithFixedDelay(new MonitorCountRun(), 5, 5, TimeUnit.SECONDS);

        while(true) {
            helloService.methodA();
            helloService.methodB();
            helloService.methodC();
        }
    }

}
